package com.hiwhitley.easy.day18;

/**
 * Created by hiwhitley on 2016/9/12.
 */
public class CountPrimes_204 {
    private static boolean isPrime(int input) {
        if (input < 2)
            return false;
        for (int i = 2; i <= (int) Math.sqrt(input); i++) {
            if (input % i == 0)
                return false;
        }
        return true;
    }

    public static int countPrimes(int n) {
        int count = 0;
        for (int i = 1; i < n; i++) {
            if (isPrime(i))
                count++;
        }
        return count;
    }

    public static void main(String[] args) {
        System.out.println(countPrimes(5));
    }
}
